package cn.net.isir.service;

import cn.net.isir.core.BasicService;
import cn.net.isir.core.SetBasicDao;
import cn.net.isir.dao.RoleDao;
import cn.net.isir.dao.UserRoleDao;
import cn.net.isir.entity.Role;
import cn.net.isir.entity.User;
import cn.net.isir.entity.UserRole;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class UserRoleService extends BasicService<UserRole> {
    @SetBasicDao
    @Resource
    private UserRoleDao userRoleDao;
    @Resource
    private RoleDao roleDao;

    /**
     * 根据用户id查询
     *
     * @param userId 用户id
     * @return role列表
     */
    public List<Role> selectRoleListByUserId(String userId) {
        UserRole userRole = new UserRole();
        userRole.setUserId(userId);
        List<UserRole> userRoleList = userRoleDao.selectList(userRole);
        List<Role> roleList = new ArrayList<>();
        userRoleList.forEach(item -> roleList.add(roleDao.selectByPrimaryKey(item.getRoleId())));
        return roleList;
    }

    /**
     * 根据用户id查询关联列表
     *
     * @param userId 用户id
     * @return 关联表列表
     */
    public List<UserRole> selectUserRoleListByUserId(String userId) {
        UserRole userRole = new UserRole();
        userRole.setUserId(userId);
        return userRoleDao.selectList(userRole);
    }
}
